<?php

class Core_Model_DbTable_Product_Buys extends Core_Model_DbTable_Product_Abstract
{
	const TABLE_NAME = 'product_buyers';
	protected $_name = self::TABLE_NAME;
	protected $_rowClass = 'Core_Model_Product_Buy';

	public function insertProductInfo(Core_Model_Product $product)
	{
		$data = $this->_getParams($product);
		$data['time_bought'] = time();
		return parent::insert($data);
	}

	public function insertProductBuys($id_product, $id_store, $id_page, $id_user)
	{
		$row = $this->createRow();
		$row->id_product = $id_product;
		$row->id_store = $id_store;
		$row->id_page = $id_page;
		$row->ip_address = $_SERVER['REMOTE_ADDR'];
		$row->id_user = $id_user;
		$row->time_bought = time();
		$row->save();

		Core_Model_DbTable_Products::getInstance()->update(
			array('number_buys' => new Zend_Db_Expr('number_buys + 1')), 
			array('id = ?' =>$id_product)
		);
	}

}